home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_08 / plauger / esxstrem.c < prev    next >
C/C++ Source or Header  |  1994-06-09  |  597b  |  29 lines

  1. -------------------------- Listing 5: streambuf extractor  ---------
  2.  
  3. // isxstream -- istream::operator>>(streambuf&)
  4. #include <istream>
  5.  
  6. istream& istream::operator>>(streambuf& sb)
  7.     {    // extract into streambuf
  8.     _Bool copied = 0;
  9.     _TRY_IO_BEGIN
  10.     if (ipfx())
  11.         {    // copy characters until failure
  12.         char buf[512];
  13.         int n;
  14.         for (; 0 < (n = rdbuf()->sgetn(buf, sizeof (buf)));
  15.             copied = 1)
  16.             _TRY_BEGIN
  17.                 if (sb.sputn(buf, n) != n)
  18.                     break;
  19.             _CATCH_ALL
  20.                 break;
  21.             _CATCH_END
  22.         }
  23.     if (!copied)
  24.         setstate(failbit);
  25.     isfx();
  26.     _CATCH_IO_END
  27.     return (*this);
  28.     }
  29.